package com.example.springboothello.util;

import org.apache.commons.mail.HtmlEmail;

public class sendEmail {

        /**
         * 发送验证码
         * @param email
         * @param msg
         * @return
         */
        public static boolean sendAuthCodeEmail(String email, String hostEmail, String hostEmailName, String msg) {
            try {
                HtmlEmail mail = new HtmlEmail();
                /*发送邮件的服务器 126邮箱为smtp.126.com,163邮箱为163.smtp.com，QQ为smtp.qq.com*/
                mail.setHostName("smtp.qq.com");
                /*不设置发送的消息有可能是乱码*/
                mail.setCharset("UTF-8");
                /*接收的邮箱*/
                mail.addTo(email);
                /*发送邮件的邮箱和发件人*/
                mail.setFrom(email, "BBX Studio Official Website");
                /*POP3/SMTP服务的密码*/
                mail.setAuthentication("2564167401@qq.com","nglojwqlpwozdhif");
                /*使用安全链接*/
                mail.setSSLOnConnect(true);
                /*设置邮件的主题*/
                mail.setSubject("BBX Studio Official Website");
                /*设置邮件的内容*/
                mail.setMsg("Name:" + hostEmailName + "\n" + "Email:" + hostEmail + "\n" + "Msg:" + msg);
                mail.send();//发送
            } catch (Exception e) {
                System.out.println(e.getMessage());
                return false;
            }
            return true;
        }

}
